using System;
using System.Data;
using System.Collections.Generic;

namespace SERP.DAO{
	/********************************BEGIN UserRolesDAO****************************************/
	///<summary>
	/// <para>Author: Auto generated class by CSharp Code Generator v2.0</para>
	/// <para>Date:09/03/2013 19:09:04</para>
	/// <para>Class Name: UserRolesDAO</para>
	/// <para>Description: Class access to table UserRoles in database. Coder should'nt code here.</para>
	///</summary>

	
	public partial class UserRolesDAO : DAOBase<UserRolesEntity>{


		#region Select functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectOneCommand</para>
		/// <para>Input: UserRoleId</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectOneCommand(int UserRoleId){
			string strSQL="SELECT  [UserRoleId],[UserId],[RoleId] FROM [UserRoles]  WHERE [UserRoles].[UserRoleId]=@UserRoleId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@UserRoleId",UserRoleId);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectOne</para>
		/// <para>Input: UserRoleId</para>
		/// <para>Output: UserRolesEntity</para>
		///</summary>
		public UserRolesEntity SelectOne(int UserRoleId){
			IDbCommand cmd=this.CreateSelectOneCommand(UserRoleId);
			return this.Select(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllCommand(){
			string strSQL="SELECT  [UserRoleId],[UserId],[RoleId] FROM [UserRoles] ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllByKeyCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyCommand(string ColumnName,object Value){
			string strSQL="SELECT  [UserRoleId],[UserId],[RoleId] FROM [UserRoles]  WHERE [UserRoles].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of UserRolesEntity</para>
		///</summary>
		public List<UserRolesEntity> SelectAll(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAllDS</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDS(){
			IDbCommand cmd=this.CreateSelectAllCommand();
			return this.SelectDS(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllFilterCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllFilterCommand(string strFilter){
			string strSQL="SELECT  [UserRoleId],[UserId],[RoleId] FROM [UserRoles]  WHERE "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateSelectAllByKeyFilterCommand</para>
		/// <para>Input: ColumnName,ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateSelectAllByKeyFilterCommand(string strFilter,string ColumnName,object Value){
			string strSQL="SELECT  [UserRoleId],[UserId],[RoleId] FROM [UserRoles]  WHERE [UserRoles].["+ColumnName+"]=@ColumnName AND "+RemoveInjection(strFilter);
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAll</para>
		/// <para>Input: </para>
		/// <para>Output: List of UserRolesEntity</para>
		///</summary>
		public List<UserRolesEntity> SelectAllFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectList(cmd);
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SelectAllDSFilter</para>
		/// <para>Input: </para>
		/// <para>Output: DataSet</para>
		///</summary>
		public DataSet SelectAllDSFilter(string strFilter){
			IDbCommand cmd=this.CreateSelectAllFilterCommand(strFilter);
			return this.SelectDS(cmd);
		}
		#endregion

		#region Insert functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateInsertCommand</para>
		/// <para>Input: UserRolesEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateInsertCommand(UserRolesEntity o){
			string strSQL="INSERT INTO [UserRoles]([UserId],[RoleId]) VALUES  (@UserId,@RoleId);SELECT  @@IDENTITY";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullUserId)
				this.CreateCommandParameter(cmd,"@UserId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@UserId",o.UserId);

			if(o.IsNullRoleId)
				this.CreateCommandParameter(cmd,"@RoleId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@RoleId",o.RoleId);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: Save</para>
		/// <para>Input: UserRolesEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Save(UserRolesEntity o){
			bool result=false;
			IDbCommand cmd=this.CreateInsertCommand(o);
			object id=this.ExecuteScalar(cmd,ref result);
			cmd.Dispose();
			try{
				o.UserRoleId=int.Parse(Convert.ToString(id));
			}
			catch{}
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: SaveList</para>
		/// <para>Input: List of UserRolesEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void SaveList(List<UserRolesEntity>list){
			foreach(UserRolesEntity o in list){
				try{
					this.Save(o);
				}
				catch{
				}
			}
		}
		#endregion

		#region Update functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateUpdateCommand</para>
		/// <para>Input: UserRolesEntity</para>
		/// <para>Output: </para>
		///</summary>
		protected IDbCommand CreateUpdateCommand(UserRolesEntity o){
			string strSQL="UPDATE  [UserRoles] SET [UserRoles].[UserId]=@UserId,[UserRoles].[RoleId]=@RoleId WHERE [UserRoles].[UserRoleId]=@UserRoleId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullUserId)
				this.CreateCommandParameter(cmd,"@UserId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@UserId",o.UserId);

			if(o.IsNullRoleId)
				this.CreateCommandParameter(cmd,"@RoleId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@RoleId",o.RoleId);

			if(o.IsNullUserRoleId)
				this.CreateCommandParameter(cmd,"@UserRoleId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@UserRoleId",o.UserRoleId);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateUpdateFieldCommand</para>
		/// <para>Input: ColumnName,ColumnValue,UserRoleId</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateUpdateFieldCommand(string ColumnName,object Value,int UserRoleId){
			string strSQL="UPDATE  [UserRoles] SET [UserRoles].["+ColumnName+"]=@ColumnName WHERE [UserRoles].[UserRoleId]=@UserRoleId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@UserRoleId",UserRoleId);



			this.CreateCommandParameter(cmd,"@ColumnName",Value);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: Update</para>
		/// <para>Input: UserRolesEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Update(UserRolesEntity o){
			IDbCommand cmd=this.CreateUpdateCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateList</para>
		/// <para>Input: List of UserRolesEntity</para>
		/// <para>Output: </para>
		///</summary>
		public void UpdateList(List<UserRolesEntity>list){
			foreach(UserRolesEntity o in list){
				try{
					this.Update(o);
				}
				catch{
				}
			}
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateUserId</para>
		/// <para>Input: NewUserId,UserRoleId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateUserId(int NewUserId,int UserRoleId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("UserId",NewUserId,UserRoleId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: UpdateRoleId</para>
		/// <para>Input: NewRoleId,UserRoleId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool UpdateRoleId(int NewRoleId,int UserRoleId){
			IDbCommand cmd=this.CreateUpdateFieldCommand("RoleId",NewRoleId,UserRoleId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Delete functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteAllCommand</para>
		/// <para>Input: </para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteAllCommand(){
			string strSQL="DELETE   FROM [UserRoles]  ";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteCommand</para>
		/// <para>Input: UserRolesEntity</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteCommand(UserRolesEntity o){
			string strSQL="DELETE   FROM [UserRoles]   WHERE [UserRoles].[UserRoleId]=@UserRoleId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			if(o.IsNullUserRoleId)
				this.CreateCommandParameter(cmd,"@UserRoleId",System.DBNull.Value);
			else
				this.CreateCommandParameter(cmd,"@UserRoleId",o.UserRoleId);


			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteAll</para>
		/// <para>Input: </para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteAll(){
			IDbCommand cmd=this.CreateDeleteAllCommand();
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateDeleteByPrimaryKeyCommand</para>
		/// <para>Input: UserRoleId</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByPrimaryKeyCommand(int UserRoleId){
			string strSQL="DELETE   FROM [UserRoles]   WHERE [UserRoles].[UserRoleId]=@UserRoleId";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@UserRoleId",UserRoleId);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: CreateDeleteByKeyCommand</para>
		/// <para>Input: ColumnName , ColumnValue</para>
		/// <para>Output: IDbCommand</para>
		///</summary>
		protected IDbCommand CreateDeleteByKeyCommand(string ColumnName,object Value){
			string strSQL="DELETE   FROM [UserRoles]   WHERE [UserRoles].["+ColumnName+"]=@ColumnName";
			IDbCommand cmd=this.CreateCommand(strSQL);
			cmd.CommandType=CommandType.Text;
			this.CreateCommandParameter(cmd,"@ColumnName",Value);



			return cmd;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: Delete</para>
		/// <para>Input: UserRolesEntity</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool Delete(UserRolesEntity o){
			IDbCommand cmd=this.CreateDeleteCommand(o);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: DeleteByID</para>
		/// <para>Input: UserRoleId</para>
		/// <para>Output: return true if succeeded else return false</para>
		///</summary>
		public bool DeleteByID(int UserRoleId){
			IDbCommand cmd=this.CreateDeleteByPrimaryKeyCommand(UserRoleId);
			bool result=this.ExcuteNoneQuery(cmd);
			cmd.Dispose();
			return result;
		}
		#endregion

		#region Select join to RolesUsers functions
		#endregion

		#region Select join to Roles functions
		#endregion

		#region Select join to Users functions
		#endregion

		#region Select,delete by UserRoleId functions
		#endregion

		#region Select,delete by UserId functions
		#endregion

		#region Select,delete by RoleId functions
		#endregion

		#region MapObject functions
		///<summary>
		/// <para>Author: Auto generated by CSharp Code Generator v2.0</para>
		/// <para>Date:09/03/2013 19:09:04</para>
		/// <para>Name: MapObject</para>
		/// <para>Input: IDataReader</para>
		/// <para>Output: UserRolesEntity</para>
		///</summary>
		protected override UserRolesEntity MapObject(IDataReader r){
			UserRolesEntity entity = new UserRolesEntity();
			try{
				if(r.FieldCount>0){
					try
					{
						int ordinal = r.GetOrdinal("UserRoleId");
						if (!r.IsDBNull(ordinal)) entity.UserRoleId = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("UserId");
						if (!r.IsDBNull(ordinal)) entity.UserId = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					try
					{
						int ordinal = r.GetOrdinal("RoleId");
						if (!r.IsDBNull(ordinal)) entity.RoleId = ((int)(r.GetValue(ordinal)));
					}
					catch{}
					return entity;
				}
			}catch{}
			return null;
		}
		#endregion
	}
	/*****************************************************************************************************/
	/**********************************END UserRolesDAOBase*****************************************/
	/*****************************************************************************************************/
}

